home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 83 / MacAddict_083_2003-07.iso / mac / Software / Development / VLC Source 0.5.3.dmg / src / misc / iso_lang.c < prev    next >
C/C++ Source or Header  |  2002-11-27  |  4KB  |  112 lines

  1. /*****************************************************************************
  2.  * iso_lang.c: function to decode language code (in dvd or a52 for instance).
  3.  *****************************************************************************
  4.  * Copyright (C) 1998-2001 VideoLAN
  5.  * $Id: iso_lang.c,v 1.8 2002/11/13 20:51:05 sam Exp $
  6.  *
  7.  * Author: StÈphane Borel <stef@via.ecp.fr>
  8.  *         Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  * 
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  23.  *****************************************************************************/
  24.  
  25. /*****************************************************************************
  26.  * Preamble
  27.  *****************************************************************************/
  28. #include <stdio.h>
  29.  
  30. #include <vlc/vlc.h>
  31.  
  32. #include "iso_lang.h"
  33.  
  34. /*****************************************************************************
  35.  * Local tables
  36.  *****************************************************************************/
  37.  
  38. #define DEFINE_LANGUAGE_CODE(engName, nativeName, iso1, iso2T, iso2B) \
  39.           { engName, nativeName, #iso1, #iso2T, #iso2B },
  40.  
  41. static const iso639_lang_t p_languages[] =
  42. {
  43. #include "iso-639_def.h"
  44.     { NULL, NULL, NULL, NULL, NULL }
  45. };
  46.  
  47. static const iso639_lang_t unknown_language =
  48.     { "Unknown", "Unknown", "??", "???", "???" };
  49.  
  50. /*****************************************************************************
  51.  * DecodeLanguage: gives the long language name from the two-letter
  52.  *                 ISO-639 code
  53.  *****************************************************************************/
  54. const char * DecodeLanguage( u16 i_code )
  55. {
  56.     const iso639_lang_t * p_lang;
  57.     u8 psz_code[3];
  58.  
  59.     psz_code[0] = i_code >> 8;
  60.     psz_code[1] = i_code & 0xff;
  61.     psz_code[2] = '\0';
  62.  
  63.     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
  64.     {
  65.         if( !strncmp( p_lang->psz_iso639_1, psz_code, 2 ) )
  66.         {
  67.             if( *p_lang->psz_native_name )
  68.             {
  69.                 return p_lang->psz_native_name;
  70.             }
  71.  
  72.             return p_lang->psz_eng_name;
  73.         }
  74.     }
  75.  
  76.     return "Unknown";
  77. }
  78.  
  79. const iso639_lang_t * GetLang_1( const char * psz_code )
  80. {
  81.     const iso639_lang_t *p_lang;
  82.  
  83.     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
  84.         if( !strncmp( p_lang->psz_iso639_1, psz_code, 2 ) )
  85.             return p_lang;
  86.  
  87.     return &unknown_language;
  88. }
  89.  
  90. const iso639_lang_t * GetLang_2T( const char * psz_code )
  91. {
  92.     const iso639_lang_t *p_lang;
  93.     
  94.     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
  95.         if( !strncmp( p_lang->psz_iso639_2T, psz_code, 3 ) )
  96.             return p_lang;
  97.  
  98.     return &unknown_language;
  99. }
  100.  
  101. const iso639_lang_t * GetLang_2B( const char * psz_code )
  102. {
  103.     const iso639_lang_t *p_lang;
  104.  
  105.     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
  106.         if( !strncmp( p_lang->psz_iso639_2B, psz_code, 3 ) )
  107.             return p_lang;
  108.  
  109.     return &unknown_language;
  110. }
  111.  
  112.